package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;


    /**
     * 根据福区域的parentId查询区域对象，如果没有
     * @param parentId
     * @return
     */
    public List<Region> listMenus(Long parentId) {
        List<Region> list = regionMapper.selectMenus(parentId);
        return list;
    }

    public void saveOrUpdate(Region region) {
        if(region.getId()==null){
            regionMapper.insert(region);
        }else{
            regionMapper.updateByPrimaryKey(region);
        }
    }

    public List<Region> listAll(Integer state) {

        return regionMapper.selectAll(state);
    }
}
